package com.pay.manager.controller.system;


import java.util.HashMap;
import java.util.Map;

import com.pay.manager.dto.UserInfoSearchDTO;
import com.pay.manager.response.PageDataResult;
import com.pay.manager.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;




/**
 * @Title: UserInfoController
 * @Description: 用户账号管理
 * @author: yjw
 * @version: 1.0
 * @date: 2020/06/11 18:16
 */
@Controller
@RequestMapping("userinfo")
public class UserInfoController {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private UserService userService;


    @RequestMapping("/userManage")
    public String toPage() {
        logger.info("进入用户信息管理");
        return "/userinfo/userManage";
    }
    
    /**
    *
    * 功能描述: 分页查询用户列表
    *
    * @param:
    * @return:
    * @auther: youqing
    * @date: 2018/11/21 11:10
    */
   @RequestMapping(value = "/getUserList", method = RequestMethod.POST)
   @ResponseBody
   public PageDataResult getUserList(@RequestParam("pageNum") Integer pageNum,
                                     @RequestParam("pageSize") Integer pageSize,/*@Valid PageRequest page,*/ UserInfoSearchDTO userSearch) {
       /*logger.info("分页查询用户列表！搜索条件：userSearch：" + userSearch + ",pageNum:" + page.getPageNum()
               + ",每页记录数量pageSize:" + page.getPageSize());*/
       PageDataResult pdr = new PageDataResult();
       try {
           if(null == pageNum) {
               pageNum = 1;
           }
           if(null == pageSize) {
               pageSize = 10;
           }
           // 获取用户列表
           pdr = userService.getUserList(userSearch, pageNum ,pageSize);
           logger.info("用户列表查询=pdr:" + pdr);

       } catch (Exception e) {
           e.printStackTrace();
           logger.error("用户列表查询异常！", e);
       }
       return pdr;
   }
   
   
   @RequestMapping(value = "/delete", method = RequestMethod.POST)
   @ResponseBody
   public Map<String,Object> delete(String uname,String operationPwd) {
       logger.info("删除用户"+uname+"]！");
       Map<String,Object> data = new HashMap();
       data = userService.delete(uname,operationPwd);
       return data;
   }

    
}
